<template>
  <div class="dialog-box" style="position: relative">
    <el-scrollbar class="custom-scroll content-box">
      <el-form
        ref="formEditCustomerInfoRef"
        :model="formData"
        :size="layoutStore.defaultFormItemSize"
        :rules="rules"
        label-width="120px"
        label-position="right"
        @submit.prevent
      >
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="名" prop="CustomerInfo.firstName">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.firstName"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓" prop="CustomerInfo.lastName">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.lastName"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="CustomerInfo.gender">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.gender"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="genderWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in genderWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期" prop="CustomerInfo.birthDate">
              <el-date-picker
                class="input-item"
                v-model="formData.CustomerInfo.birthDate"
                type="date"
                placeholder=""
                :clearable="true"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电子邮件" prop="CustomerInfo.email">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.email"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话号码" prop="CustomerInfo.phoneNumber">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.phoneNumber"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件类型" prop="CustomerInfo.idType">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.idType"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="idTypeWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in idTypeWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码" prop="CustomerInfo.idNumber">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.idNumber"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="国籍" prop="CustomerInfo.nationality">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.nationality"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="nationalityWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in nationalityWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省" prop="CustomerInfo.provinceCode">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.provinceCode"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="provinceCodeWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in provinceCodeWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="市" prop="CustomerInfo.cityCode">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.cityCode"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="cityCodeWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in cityCodeWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区" prop="CustomerInfo.districtCode">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.districtCode"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="districtCodeWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in districtCodeWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="详细地址1" prop="CustomerInfo.detailedAddress1">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.detailedAddress1"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="详细地址2" prop="CustomerInfo.detailedAddress2">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.detailedAddress2"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职业" prop="CustomerInfo.occupation">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.occupation"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="CustomerInfo.companyName">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.companyName"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收入范围" prop="CustomerInfo.incomeRange">
              <el-select
                class="input-item"
                v-model="formData.CustomerInfo.incomeRange"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="incomeRangeWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in incomeRangeWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="紧急联系人姓名" prop="CustomerInfo.emergencyContactName">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.emergencyContactName"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他备注信息" prop="CustomerInfo.remark">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.remark"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="紧急联系人电话" prop="CustomerInfo.emergencyContactPhone">
              <el-input
                class="input-item"
                v-model="formData.CustomerInfo.emergencyContactPhone"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-scrollbar>
    <el-row class="footer-box" type="flex" justify="end" align="middle">
      <el-button :size="layoutStore.defaultFormItemSize" @click="onCancel()">取消</el-button>
      <el-button :size="layoutStore.defaultFormItemSize" type="primary" @click="onSubmitCustomerInfoClick()">保存</el-button>
    </el-row>
  </div>
</template>

<script lang="ts">
export default {
  name: 'formEditCustomerInfo',
};
</script>

<script setup lang="ts">
import { DialogProp } from '@/components/Dialog/types';
import { VxeColumn, VxeTable } from 'vxe-table';
import { ANY_OBJECT } from '@/types/generic';
import { DictData, DictionaryBase } from '@/common/staticDict/types';
import { ElMessage, ElMessageBox, UploadFile } from 'element-plus';
import { useRoute, useRouter } from 'vue-router';
import { useCommon } from '@/common/hooks/useCommon';
import { useLayoutStore, useStaticDictStore } from '@/store';
import { useDownload } from '@/common/hooks/useDownload';
import { useDropdown } from '@/common/hooks/useDropdown';
import { DropdownOptions, ListData } from '@/common/types/list';
import { useTable } from '@/common/hooks/useTable';
import { TableOptions } from '@/common/types/pagination';
import { useUpload } from '@/common/hooks/useUpload';
import { useUploadWidget } from '@/common/hooks/useUploadWidget';
import { DictionaryController } from '@/api/system';
import { treeDataTranslate, findItemFromList, findTreeNodePath, findTreeNode, stringCase } from '@/common/utils';
import { CustomerAccountData } from '@/api/generated/customerAccountController';
import { CustomerInfoData } from '@/api/generated/customerInfoController';
import { CustomerAccountController, CustomerInfoController } from '@/api/generated';

const router = useRouter();
const route = useRoute();
const layoutStore = useLayoutStore();
const { downloadFile } = useDownload();
const { getUploadHeaders, getUploadActionUrl, fileListToJson, parseUploadData, getPictureList } = useUpload();
const {
  Delete,
  Search,
  Edit,
  Plus,
  Refresh,
  Picture,
  Dialog,
  mainContextHeight,
  clientHeight,
  checkPermCodeExist,
  parseParams,
  parseArrayParams,
  formatDateByStatsType,
  getDateRangeFilter,
} = useCommon();
// 静态字典
const { staticDict: StaticDict } = useStaticDictStore();

const props = withDefaults(
  defineProps<{
    subPage?: number | string | boolean;
    customerId?: ANY_OBJECT;
    saveOnSubmit?: boolean;
    rowData?: ANY_OBJECT;
    // 当使用Dialog.show弹出组件时，须定义该prop属性，以便对dialog进行回调
    dialog?: DialogProp<ANY_OBJECT[]>;
  }>(),
  {
    subPage: 0,
    customerId: undefined,
    saveOnSubmit: true,
    rowData: undefined,
    dialog: undefined,
  },
);

const formEditCustomerInfoRef = ref();
// 表单数据定义
type FormEditCustomerInfoData = {
  CustomerInfo: CustomerInfoData;
};
// 表单数据
const formData = reactive<FormEditCustomerInfoData>({
  CustomerInfo: {
    // 唯一标识符
    customerId: undefined,
    // 名
    firstName: undefined,
    // 姓
    lastName: undefined,
    // 电子邮件
    email: undefined,
    // 电话号码
    phoneNumber: undefined,
    // 性别
    gender: undefined,
    // 出生日期
    birthDate: undefined,
    // 证件类型
    idType: undefined,
    // 证件号码
    idNumber: undefined,
    // 国籍
    nationality: undefined,
    // 省行政区划代码
    provinceCode: undefined,
    // 市行政区划代码
    cityCode: undefined,
    // 区行政区划代码
    districtCode: undefined,
    // 详细地址1
    detailedAddress1: undefined,
    // 详细地址2
    detailedAddress2: undefined,
    // 完整地址
    fullAddress: undefined,
    // 职业
    occupation: undefined,
    // 公司名称
    companyName: undefined,
    // 收入范围
    incomeRange: undefined,
    // 紧急联系人姓名
    emergencyContactName: undefined,
    // 紧急联系人电话
    emergencyContactPhone: undefined,
    // 注册日期
    registrationDate: undefined,
    // 最后登录时间
    lastLogin: undefined,
    // 用户状态
    status: undefined,
    // 其他备注信息
    remark: undefined,
    // 创建人
    createdBy: undefined,
    // 创建时间
    createdTime: undefined,
    // 更新人
    updatedBy: undefined,
    // 更新时间
    updatedTime: undefined,
    // 删除标志
    deletedFlag: undefined,
    // 客户银行卡数据
    customerAccountList: [],
  },
},
);
// 表单验证规则
const rules = reactive({
  'CustomerInfo.birthDate': [
  ],
  'CustomerInfo.companyName': [
  ],
  'CustomerInfo.occupation': [
  ],
  'CustomerInfo.firstName': [
  ],
  'CustomerInfo.districtCode': [
  ],
  'CustomerInfo.cityCode': [
  ],
  'CustomerInfo.email': [
  ],
  'CustomerInfo.detailedAddress2': [
  ],
  'CustomerInfo.lastName': [
  ],
  'CustomerInfo.detailedAddress1': [
  ],
  'CustomerInfo.remark': [
  ],
  'CustomerInfo.idNumber': [
  ],
  'CustomerInfo.emergencyContactName': [
  ],
  'CustomerInfo.idType': [
  ],
  'CustomerInfo.incomeRange': [
  ],
  'CustomerInfo.provinceCode': [
  ],
  'CustomerInfo.nationality': [
  ],
  'CustomerInfo.emergencyContactPhone': [
  ],
  'CustomerInfo.gender': [
  ],
  'CustomerInfo.phoneNumber': [
    //{type: 'string', pattern: rules.pattern.mobie, message: '请输入正确的手机号码', trigger: 'blur'}
  ],
});

const onCancel = () => {
  if (props.dialog) {
    props.dialog.cancel();
  }
};

const isEdit = computed(() => {
  return props.saveOnSubmit ? props.customerId != null : props.rowData != null;
});

// 初始化页面数据
const loadCustomerInfoData = () => {
  return new Promise<void>((resolve, reject) => {
    if (!isEdit.value) {
      resolve();
      return;
    }
    if (!props.saveOnSubmit && props.rowData != null) {
      formData.CustomerInfo = JSON.parse(JSON.stringify(props.rowData));
      resolve();
      return;
    }
    let params: ANY_OBJECT = {
      customerId: props.customerId
    };
    CustomerInfoController.view(params).then(res => {
      formData.CustomerInfo = { ...res.data };
      resolve();
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 性别下拉数据获取函数
 */
const loadGenderDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.Gender.getList(),
  });
};
// 性别配置参数
const genderOptions: DropdownOptions<DictData> = {
  loadData: loadGenderDropdownList,
  isTree: false,
};
// 性别下拉组件
const genderWidget = useDropdown(genderOptions);
const { dropdownList: genderWidgetDropdownList } = genderWidget
/**
 * 证件类型下拉数据获取函数
 */
const loadIdTypeDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.CertType.getList(),
  });
};
// 证件类型配置参数
const idTypeOptions: DropdownOptions<DictData> = {
  loadData: loadIdTypeDropdownList,
  isTree: false,
};
// 证件类型下拉组件
const idTypeWidget = useDropdown(idTypeOptions);
const { dropdownList: idTypeWidgetDropdownList } = idTypeWidget
/**
 * 国籍下拉数据获取函数
 */
const loadNationalityDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'Country', itemIdType: 'String' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 国籍配置参数
const nationalityOptions: DropdownOptions<DictData> = {
  loadData: loadNationalityDropdownList,
  isTree: false,
};
// 国籍下拉组件
const nationalityWidget = useDropdown(nationalityOptions);
const { dropdownList: nationalityWidgetDropdownList } = nationalityWidget
/**
 * 省下拉数据获取函数
 */
const loadProvinceCodeDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {
    };
    DictionaryController.dictAreaCodeByParentId(params).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 省配置参数
const provinceCodeOptions: DropdownOptions<DictData> = {
  loadData: loadProvinceCodeDropdownList,
  isTree: false,
};
// 省下拉组件
const provinceCodeWidget = useDropdown(provinceCodeOptions);
const { dropdownList: provinceCodeWidgetDropdownList } = provinceCodeWidget
/**
 * 市下拉数据获取函数
 */
const loadCityCodeDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {
      parentId: formData.CustomerInfo.provinceCode,
    };
    // 判断上级组件是否为空
    if (params.parentId == null || params.parentId === '') {
      resolve([]);
      return;
    }
    DictionaryController.dictAreaCodeByParentId(params).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 市配置参数
const cityCodeOptions: DropdownOptions<DictData> = {
  loadData: loadCityCodeDropdownList,
  isTree: false,
};
// 市下拉组件
const cityCodeWidget = useDropdown(cityCodeOptions);
const { dropdownList: cityCodeWidgetDropdownList } = cityCodeWidget
/**
 * 区下拉数据获取函数
 */
const loadDistrictCodeDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {
      parentId: formData.CustomerInfo.cityCode,
    };
    // 判断上级组件是否为空
    if (params.parentId == null || params.parentId === '') {
      resolve([]);
      return;
    }
    DictionaryController.dictAreaCodeByParentId(params).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 区配置参数
const districtCodeOptions: DropdownOptions<DictData> = {
  loadData: loadDistrictCodeDropdownList,
  isTree: false,
};
// 区下拉组件
const districtCodeWidget = useDropdown(districtCodeOptions);
const { dropdownList: districtCodeWidgetDropdownList } = districtCodeWidget
/**
 * 收入范围下拉数据获取函数
 */
const loadIncomeRangeDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'MonthIncomeRange', itemIdType: 'String' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 收入范围配置参数
const incomeRangeOptions: DropdownOptions<DictData> = {
  loadData: loadIncomeRangeDropdownList,
  isTree: false,
};
// 收入范围下拉组件
const incomeRangeWidget = useDropdown(incomeRangeOptions);
const { dropdownList: incomeRangeWidgetDropdownList } = incomeRangeWidget
const onUploadError = () => {
  ElMessage.error('文件上传失败');
};
const onUploadLimit = () => {
  ElMessage.error('已经超出最大上传个数限制');
};
const refreshFormEditCustomerInfo = () => {
  // 刷新段落
};
/**
 * 重置过滤值
 */
const resetFormEditCustomerInfo = () => {
  refreshFormEditCustomerInfo();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormEditCustomerInfo();
};
/**
 * 保存
 */
const onSubmitCustomerInfoClick = () => {
  formEditCustomerInfoRef.value.validate((valid) => {
    if (!valid) return;
    // 级联操作
    if (!props.saveOnSubmit) {
      let retFormData = {
        ...formData.CustomerInfo
      };
    retFormData.genderDictMap = findItemFromList(genderWidgetDropdownList.value, retFormData.gender, 'id');
    retFormData.idTypeDictMap = findItemFromList(idTypeWidgetDropdownList.value, retFormData.idType, 'id');
    retFormData.nationalityDictMap = findItemFromList(nationalityWidgetDropdownList.value, retFormData.nationality, 'id');
    retFormData.provinceCodeDictMap = findItemFromList(provinceCodeWidgetDropdownList.value, retFormData.provinceCode, 'id');
    retFormData.cityCodeDictMap = findItemFromList(cityCodeWidgetDropdownList.value, retFormData.cityCode, 'id');
    retFormData.districtCodeDictMap = findItemFromList(districtCodeWidgetDropdownList.value, retFormData.districtCode, 'id');
    retFormData.incomeRangeDictMap = findItemFromList(incomeRangeWidgetDropdownList.value, retFormData.incomeRange, 'id');
  props.dialog?.submit(retFormData);
      return;
    }
    let params: ANY_OBJECT = {
      customerInfoDto: {
        customerId: formData.CustomerInfo.customerId,
        firstName: formData.CustomerInfo.firstName,
        lastName: formData.CustomerInfo.lastName,
        email: formData.CustomerInfo.email,
        phoneNumber: formData.CustomerInfo.phoneNumber,
        gender: formData.CustomerInfo.gender,
        birthDate: formData.CustomerInfo.birthDate,
        idType: formData.CustomerInfo.idType,
        idNumber: formData.CustomerInfo.idNumber,
        nationality: formData.CustomerInfo.nationality,
        provinceCode: formData.CustomerInfo.provinceCode,
        cityCode: formData.CustomerInfo.cityCode,
        districtCode: formData.CustomerInfo.districtCode,
        detailedAddress1: formData.CustomerInfo.detailedAddress1,
        detailedAddress2: formData.CustomerInfo.detailedAddress2,
        fullAddress: formData.CustomerInfo.fullAddress,
        occupation: formData.CustomerInfo.occupation,
        companyName: formData.CustomerInfo.companyName,
        incomeRange: formData.CustomerInfo.incomeRange,
        emergencyContactName: formData.CustomerInfo.emergencyContactName,
        emergencyContactPhone: formData.CustomerInfo.emergencyContactPhone,
        registrationDate: formData.CustomerInfo.registrationDate,
        lastLogin: formData.CustomerInfo.lastLogin,
        status: formData.CustomerInfo.status,
        remark: formData.CustomerInfo.remark,
        createdBy: formData.CustomerInfo.createdBy,
        createdTime: formData.CustomerInfo.createdTime,
        updatedBy: formData.CustomerInfo.updatedBy,
        updatedTime: formData.CustomerInfo.updatedTime,
      }
    };

    let httpCall = isEdit.value ? CustomerInfoController.update : CustomerInfoController.add;
    httpCall(params).then(res => {
      ElMessage.success('保存成功');
      props.dialog?.submit();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  });
};
const formInit = () => {
  loadCustomerInfoData().then(res => {
    genderWidget.onVisibleChange(true).catch(e => {console.error(e)});
    idTypeWidget.onVisibleChange(true).catch(e => {console.error(e)});
    nationalityWidget.onVisibleChange(true).catch(e => {console.error(e)});
    provinceCodeWidget.onVisibleChange(true).catch(e => {console.error(e)});
    cityCodeWidget.onVisibleChange(true).catch(e => {console.error(e)});
    watch(
      () => formData.CustomerInfo.provinceCode,
      () => {
        formData.CustomerInfo.cityCode = undefined;
        cityCodeWidget.dirty.value = true;
      }
    );
    districtCodeWidget.onVisibleChange(true).catch(e => {console.error(e)});
    watch(
      () => formData.CustomerInfo.cityCode,
      () => {
        formData.CustomerInfo.districtCode = undefined;
        districtCodeWidget.dirty.value = true;
      }
    );
    incomeRangeWidget.onVisibleChange(true).catch(e => {console.error(e)});
    if (isEdit.value) refreshFormEditCustomerInfo();
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};

onMounted(() => {
  formInit();
});
</script>
